/**
 * sysHandlerErrorLogServiceImpl
 * 项目名称:分秒金融
 *
 * @author lunli
 *
 * 功能描述:错误处理管理
 * 
 * 历史版本:2017-04-25 v1.0.0 lunli  创建:
 * 
 */
package com.fmjr.sys.sysHandlerErrorLog.service.impl;

import com.fmjr.common.base.exception.BusinessException;
import com.fmjr.common.base.util.Pager;
import com.fmjr.common.util.Constants;
import com.fmjr.common.util.SqlUtil;
import com.fmjr.sys.sysHandlerErrorLog.bean.SysHandlerErrorLog;
import com.fmjr.sys.sysHandlerErrorLog.dao.SysHandlerErrorLogDao;
import com.fmjr.sys.sysHandlerErrorLog.service.ISysHandlerErrorLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;


@Service("sysHandlerErrorLogService")
public class  SysHandlerErrorLogServiceImpl implements ISysHandlerErrorLogService {
	

	@Autowired
    private SysHandlerErrorLogDao sysHandlerErrorLogDao;

	/**
	 * 根据条件查询错误处理记录
	 * @author lunli
	 * @param  pager
	 * @return SysHandlerErrorLogList
	 * @throws BusinessException
	 */
	public void selectSysHandlerErrorLogList(Pager<SysHandlerErrorLog> pager) throws BusinessException{
		int totalCount = sysHandlerErrorLogDao.selectSysHandlerErrorLogCount(pager);
		int numPerPage = SqlUtil.checkPageSize(pager.getNumPerPage());
		int currentPage = SqlUtil.checkPageCurrent(totalCount, numPerPage, pager.getPageNum());
		pager.setLimitStart(SqlUtil.countOffset(currentPage, numPerPage));
		pager.setPageSize(numPerPage);
		pager.setCurrentPage(currentPage);
		pager.setTotalCount(totalCount);
		pager.setTotalPage(totalCount%numPerPage==0?totalCount/numPerPage:totalCount/numPerPage+1);
		List<SysHandlerErrorLog> list = sysHandlerErrorLogDao.selectSysHandlerErrorLogList(pager);
		pager.setList(list);
	}
	
	/**
	 * 根据ID查询错误处理记录
	 * @author lunli
	 * @param id
	 * @return domain
	 * @throws BusinessException
	 */
	public SysHandlerErrorLog selectSysHandlerErrorLogById(Long id) throws BusinessException{
		return sysHandlerErrorLogDao.selectSysHandlerErrorLogById(id);
	}

	/**
	 *  删除错误处理记录
	 * @author lunli	 
	 * @param id
	 * @throws BusinessException
	 */
	@Transactional(rollbackFor=BusinessException.class)
	public int deleteSysHandlerErrorLogById(Long id) throws BusinessException{
		return sysHandlerErrorLogDao.deleteSysHandlerErrorLogById(id);
	}
	
	/**
	 * 修改错误处理记录
	 * @author lunli
	 * @param sysHandlerErrorLog
	 * @throws BusinessException
	 */
	@Transactional(rollbackFor=BusinessException.class)
	public int updateSysHandlerErrorLog(SysHandlerErrorLog sysHandlerErrorLog) throws BusinessException{
		return sysHandlerErrorLogDao.updateSysHandlerErrorLogSelective(sysHandlerErrorLog);
	}

	/**
	 * 新增错误处理记录
	 * @author lunli
	 * @param sysHandlerErrorLog
	 * @return
	 * @throws BusinessException
	 */
	@Transactional(rollbackFor=BusinessException.class)
	public int createSysHandlerErrorLog(SysHandlerErrorLog sysHandlerErrorLog) throws BusinessException{
		return sysHandlerErrorLogDao.createSysHandlerErrorLog(sysHandlerErrorLog);
	}

	@Override
	public int createSysHandlerErrorLog(String errorType,String order, String className, String errorCode, String errorMsg)
			throws BusinessException {
		SysHandlerErrorLog handlerErrorLog = new SysHandlerErrorLog();
		handlerErrorLog.setErrorType(errorType);
		handlerErrorLog.setCauseClass(className);
		handlerErrorLog.setCreateDate(new Date());
		handlerErrorLog.setOrderNo(order);
		handlerErrorLog.setErrorCode(errorCode);
		handlerErrorLog.setErrorMsg(errorMsg);
		handlerErrorLog.setStatus(Constants.CommonStatus.COMMON_STATUS_false);
		return sysHandlerErrorLogDao.createSysHandlerErrorLog(handlerErrorLog);
	}
	

	

}
